<template>
  <div id="app">
    <div class="content">
      <div class="result">
        <div class="title">请假记录</div>
        <div class="recording">
          <el-table :data="tableData" border style="width: 100%">
            <el-table-column fixed prop="date" label="申请日期" width="250">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="250">
            </el-table-column>
            <el-table-column prop="start_time" label="开始时间" width="250">
            </el-table-column>
            <el-table-column prop="end_time" label="结束时间" width="250">
            </el-table-column>
            <el-table-column prop="type" label="类型" width="200">
            </el-table-column>
            <el-table-column prop="result" label="审核结果" width="200">
            </el-table-column>

            <el-table-column label="操作">
              <template slot-scope="scope">
                <!-- <el-button
                  @click="handleClick(scope.row)"
                  type="text"
                  size="small"
                  >查看</el-button
                > -->
                <el-button type="text" size="small" @click="open(scope.row)"
                  >审核</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-dialog
            :title="this.title"
            :visible.sync="dialogVisible"
            width="30%"
          >
            <span>{{this.content}}</span>
            <span slot="footer" class="dialog-footer">
              <el-button @click="no()">驳回</el-button>
              <el-button type="primary" @click="ok()"
                >通过</el-button
              >
            </span>
          </el-dialog>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  created: function () {
    this.getIndex();
  },
  methods: {
    getIndex() {
      this.$api({
        url: "/index/askforleave_teacher",
        method: "get",
        success: (data) => {
          console.log(data);
          let tmp;
          data.forEach((value) => {
            if (value.allow == 0) {
              tmp = "未审核";
            } else if (value.allow == 1) {
              tmp = "审核未通过";
            } else {
              tmp = "审核通过";
            }
            var listdata = {
              date: value.create_time.substring(0, 10),
              type: value.type,
              start_time: value.start_time,
              end_time: value.end_time,
              result: tmp,
              name: value.name,
              content:value.content,
              id:value.id,
            };
            this.tableData.push(listdata);
            listdata = "";
          });
        },
      });
    },
    open(row) {
      console.log(row);
      this.dialogVisible = true;
      this.content=row.content,
      this.title=row.type
      this.id=row.id
    },
    ok(){
      this.$api({
        url: "/index/askforleave_ok",
        method: "post",
        data:{id:this.id},
        success: (data) => {
          this.tableData=[]
          this.getIndex()
          this.dialogVisible=false
        },
      });
    },
    no(){
      this.$api({
        url: "/index/askforleave_no",
        method: "post",
        data:{id:this.id},
        success: (data) => {
          this.tableData=[]
          this.getIndex()
          this.dialogVisible=false
        },
      });
    }
   
  },
  data() {
    return {
      id:"",
      title:"",
      content:"",
      dialogVisible: false,
      // 选项
      options: [
        {
          value: "选项1",
          label: "病假",
        },
        {
          value: "选项2",
          label: "事假",
        },
      ],
      value: "",
      // 日期
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      value1: "",
      value2: "",
      tableData: [],
    };
  },
};
</script>

<style lang="scss" scoped>
#app {
  border: 2px solid #ccc;
  .write {
    font-size: 20px;
    text-align: center;
    height: 50px;
    font-weight: bold;
    line-height: 50px;
    border-bottom: 1px solid #ccc;
  }
  .content {
    padding: 0 20px;

    .el-select {
      padding: 10px 0;
    }
    .block {
      padding: 10px 0;
    }
    .reason {
      padding: 10px 0;
      textarea {
        width: 90%;
        height: 50px;
        outline-style: none;
        resize: none;
        display: block;
        border: 1px solid #dcdfe6;
      }
    }
    .btn {
      padding: 10px 0;
      padding-right: 120px;
      display: flex;
      justify-content: flex-end;
    }
    .result {
      padding-bottom: 50px;
      .title {
        margin: 30px 0;
        padding: 10px;
        font-size: 20px;
        color: #ccc;
        transition: all 0.5s ease;
        text-align: center;
        &::before {
          content: "";
          display: inline-block;
          height: 2px;
          width: 50px;
          background: #ccc;
          position: relative;
          top: -5px;
          transition: all 0.5s ease;
        }
        &::after {
          content: "";
          display: inline-block;
          height: 2px;
          width: 50px;
          background: #ccc;
          position: relative;
          top: -5px;
          transition: all 0.5s ease;
        }
      }
      &:hover .title {
        color: skyblue;
        transition: all 0.5s ease;
      }
      &:hover .title::before {
        width: 200px;
        background: skyblue;
        transition: all 0.5s ease;
      }
      &:hover .title::after {
        width: 200px;
        background: skyblue;
        transition: all 0.5s ease;
      }
    }
  }
}
</style>
